const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const getInboundGuidanceForSKU = {};
getInboundGuidanceForSKU.generateOption = function(seller_id, mws_auth_token, marketplaceId, sellerSKUIdList){
  let baseOption = {
    'Version': '2010-10-01',
    'Action': 'GetInboundGuidanceForSKU',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'MarketplaceId': marketplaceId,
  };

  if (sellerSKUIdList) {
    let keyPrefix = "SellerSKUList.Id";
    sellerSKUIdList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item;
    });
  }

  return baseOption;
};

getInboundGuidanceForSKU._ = function(options) {
  if (!isProduction) {
    return amazonMws.fulfillmentInboundShipment.search(options);
  } else {
    console.error("bot not implemented!");
  }
};

getInboundGuidanceForSKU.getInboundGuidanceForSKU = function(seller_id, mws_auth_token, marketplaceId, sellerSKUIdList) {
  return this._(this.generateOption(seller_id, mws_auth_token, marketplaceId, sellerSKUIdList));
};

module.exports = getInboundGuidanceForSKU;